# 选择官方 Golang 镜像作为构建环境
FROM golang:1.24.1-alpine AS builder

# 创建工作目录
WORKDIR /app

# 复制项目源码
COPY . .

# 下载依赖（如果有 go.mod）
RUN go env -w GOPROXY=https://goproxy.cn,direct && \
    go mod tidy

# 构建可执行文件，输出到 /app/bin/httpsqs_exporter
RUN go build -o bin/redis_key_exporter ./main/main.go

# 选择一个更小的基础镜像用于运行时
FROM alpine:latest

# 创建工作目录
WORKDIR /app

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories &&\
    apk add --no-cache ca-certificates bash

COPY --from=builder /app/bin/redis_key_exporter /app/redis_key_exporter

# 复制 entrypoint 脚本
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh && chmod +x /app/redis_key_exporter


EXPOSE 9100

ENTRYPOINT ["/app/entrypoint.sh"]
